<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>优惠券管理</title>
	<meta name="decorator" content="default"/>
<link href="${ctxStatic}/jquery-ui-1.12.1/jquery-ui.min.css" rel="stylesheet" />
<script src="${ctxStatic}/jquery-ui-1.12.1/jquery-ui.min.js" type="text/javascript"></script>
<script src="${ctxStatic}/js/messages_zh.js" type="text/javascript"></script>
<script src="${ctxStatic}/js/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	
	
/*表单验证*/
$('#inputForm').validate({
    rules:{
     name:"required",
     stock: "required",
     type: "required",
     price:"required",
     minPrice:"required",
     limit:"required",
     dateType:"required",
     timeBegin:"required",
     timeOver:"required",
     dateLimit:"required"
    },	    
   messages:{
   	name: "请输入优惠券名",
   	stock:"请填写发放总量",
   	type:"请选择优惠形式",
   	price:"请输入优惠面值或折扣",
   	minPrice:"请输入使用门槛",
   	limit:"请输入每人限领",
   	dateType:"请选择限期方式",
   	timeBegin:"请选择开始时间",
    timeOver:"请选择结束时间",
    dateLimit:"请输入生效天数"
   }
   
});		

 $('#ccc').bind('change',function(){
	var value = $(this).find('option:selected').val();
	if (value == 0){
		document.getElementById("startTimes").style.display="";
		document.getElementById("endTimes").style.display="";
		document.getElementById("yxDays").style.display="none";
	}else if(value == 2 || value ==1){
		document.getElementById("startTimes").style.display="none";
		document.getElementById("endTimes").style.display="none";
		document.getElementById("yxDays").style.display="";
	}else {
		document.getElementById("startTimes").style.display="none";
		document.getElementById("endTimes").style.display="none";
		document.getElementById("yxDays").style.display="none";
	}
}); 
	
});



</script>

</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/cupons/tCupons/list">优惠券列表</a></li>
		<li class="active"><a href="${ctx}/cupons/tCupons/form">优惠券编辑</a></li>
	</ul>
	<form:form id="inputForm" modelAttribute="tCuponsInfo"
		action="${ctx}/cupons/tCupons/save" method="post" class="form-horizontal">
		<form:hidden path="cuponsId" />
		<div class="control-group">
			<label class="control-label">优惠券名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="20"
						class="span4 required" name="name" />
						
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">发放总量：</label>
			<div class="controls">
				<form:input path="stock" htmlEscape="false" maxlength="20"
						class="span4 required" name="stock"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">优惠形式：</label>
			<div class="controls">
				<form:select path="type" class="span4" name="type">
					<option value="">--请选择--</option>
					<option value="0" <c:if test="${ '0' eq tCuponsInfo.type}">selected="selected"</c:if>>满减</option>
					<option value="1" <c:if test="${ '1' eq tCuponsInfo.type}">selected="selected"</c:if>>折扣</option>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">折扣/面值</label>
			<div class="controls">
				<form:input path="price" htmlEscape="false" maxlength="20"
						class="span4 required" name="price" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">使用门槛：</label>
			<div class="controls">
				<form:input path="minPrice" htmlEscape="false" maxlength="20"
						class="span4 required" name="minprice"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">每人限领：</label>
			<div class="controls">
				<form:input path="limit" htmlEscape="false" maxlength="20"
						class="span4 required" name="limit"/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">限期方式：</label>
			<div class="controls">
				<form:select path="dateType" class="span4" name="datetype" id="ccc">
					<option value="0" <c:if test="${ '0' eq tCuponsInfo.dateType}">selected="selected"</c:if>>固定日期</option>
					<option value="1" <c:if test="${ '1' eq tCuponsInfo.dateType}">selected="selected"</c:if>> 领到券当日开始n天内生效</option>
					<option value="2" <c:if test="${ '2' eq tCuponsInfo.dateType}">selected="selected"</c:if>> 领到券次日开始n天内生效</option>
				</form:select>
			</div>
		</div>
		
		<c:if test="${ '0' eq tCuponsInfo.dateType}">
		<div class="control-group" id="startTimes" style="display:">
			<label class="control-label">有效期开始时间：</label>
			<div class="controls">
				<input name="timeBegin" id="begindate" type="text" readonly="readonly" 
					class="span4 Wdate"
					value="<fmt:formatDate value="${tCuponsInfo.timeBegin}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		
		<div class="control-group" id="endTimes" style="display:">
			<label class="control-label">有效期结束时间：</label>
			<div class="controls">
				<input name="timeOver" id="overdate" type="text" readonly="readonly" 
					class="span4 Wdate"
					value="<fmt:formatDate value="${tCuponsInfo.timeOver}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		
		<div class="control-group" id="yxDays" style="display:none">
			<label class="control-label">生效天数：</label>
			<div class="controls">
				<form:input path="dateLimit" htmlEscape="false" maxlength="20"
						class="span4 required" />
			</div>
		</div>
		
		</c:if>
		<c:if test="${ '1' eq tCuponsInfo.dateType||'2' eq tCuponsInfo.dateType}">
		
		<div class="control-group" id="startTimes" style="display:none">
			<label class="control-label">有效期开始时间：</label>
			<div class="controls">
				<input name="timeBegin" id="begindate" type="text" readonly="readonly" 
					class="span4 Wdate"
					value="<fmt:formatDate value="${tCuponsInfo.timeBegin}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		
		<div class="control-group" id="endTimes" style="display:none">
			<label class="control-label">有效期结束时间：</label>
			<div class="controls">
				<input name="timeOver" id="overdate" type="text" readonly="readonly" 
					class="span4 Wdate"
					value="<fmt:formatDate value="${tCuponsInfo.timeOver}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		
		<div class="control-group" id="yxDays" style="display:">
			<label class="control-label">生效天数：</label>
			<div class="controls">
				<form:input path="dateLimit" htmlEscape="false" maxlength="20"
						class="span4 required" />
			</div>
		</div>
		</c:if>
		<div class="control-group">
			<label class="control-label">使用说明：</label>
			<div class="controls">
				<form:textarea path="instruction" htmlEscape="false" maxlength="20"
						class="span4 " />
			</div>
		</div>
		<div class="form-actions">
				<input id="btnSubmit" class="btn btn-primary" type="submit"
					value="保 存" />&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回"
				onclick="history.go(-1)" />
		</div>
	</form:form>	
</body>
</html>